<?php
if (isset($InputData["list_type"])) {
    require_once("{$CfgPara->root}/model/topic.m.php");
    $myTopic = new topic_m($CfgPara->database);
    $myTopic->is_tablet = $isTablet;
    $topic_show_view = '';
    /**
     * 查询列表id
     */
    $topic_list_id = 0;
    if ($InputData["list_type"] == topic_m::ListMine //我参与的专题
        || $InputData["list_type"] == topic_m::ListJoinSele //投稿专题选择
        || $InputData["list_type"] == topic_m::ListEdit //管理员编辑专题列表
    ) {
        if (isset($InputData['works_user_id'])) {
            //在个人主页中 显示加入的专题
            $topic_list_id = $InputData['works_user_id'];
            $topicCount = $myTopic->topic_count($topic_list_id);
            if ($isTablet === FALSE) {
                $tittleText = '他加入的专题';
                require("{$viewRoot}view/tittle_back_bar{$viewEx}");
            } else {
                $topic_show_view = '_show';
            }
        } elseif (isset($_SESSION['user_id']) && $_SESSION['user_id'] > 0) {
            if ($InputData["list_type"] == topic_m::ListMine) {
                $searchTittle = '我的专题';
                $topic_list_id = $_SESSION['user_id'];
                if (!isset($InputData['search_text'])) {
                    $topicCount = $myTopic->topic_count($_SESSION['user_id']);
                } else {
                    //如果为搜索，查询时才确定总数
                    $topicCount = -1;
                }
            } elseif ($InputData["list_type"] == topic_m::ListJoinSele) {
                if (isset($InputData["work_id"])) {
                    $searchTittle = '请选择专题';
                    $topic_list_id = $InputData["work_id"];
                    $topicCount = $myTopic->topic_count();
                } else {
                    echo('作品信息错误 无法进行投稿');
                    goto page_end;
                }
            } elseif ($InputData['list_type'] == topic_m::ListEdit) {
                $searchTittle = '专题编辑';
                $topicCount = $myTopic->topic_count();
            }
            if (!isset($InputData['page_change'])) {
                require("{$viewRoot}search_bar{$viewEx}");
            }
        } else {
            require("{$CfgPara->root}/controller/user_login.c.php");
            goto page_end;
        }
    } elseif ($InputData["list_type"] == topic_m::ListCheck || //管理员待审核列表
        $InputData["list_type"] == topic_m::ListChecked
    ) //管理员已审核列表
    {
        if (!isset($_SESSION['user_level']) || $_SESSION['user_level'] < 90 ||
            !isset($_SESSION['user_admin']) || $_SESSION['user_admin'] != 1
        ) {
            echo("权限不足 仅管理员可进行专题管理");
            goto page_end;
        }
        if (!isset($InputData['page_change'])) {
            $searchTittle = '专题审核';
            require("{$viewRoot}search_bar{$viewEx}");
        } else {
            $topic_show_view = '_attention';
        }
        $topic_list_id = 0;
        $topicCount = -1; //数量将是查询时确定
    } elseif ($InputData["list_type"] == topic_m::ListPublic) {
        //仅搜索时 会连接到此
        $topicCount = -1; //搜索时数量将是查询时确定
    } else {
        exit("专题列表类型错误");
    }
    if ($topicCount > 0 || $topicCount == -1) //20170130 修改 $topicCount=-1表示查询时确定数量
    {
        if (isset($InputData['page_change']) && $InputData['page_change'] > 0) {
            $page_index = $InputData['page_change'];
        } else {
            $page_index = 1;
        }
        if (isset($InputData['search_text'])
            && isset($InputData['search_content'])
            && $InputData['search_content'] == 'topic_list'
        ) {
            //如果有搜索内容 则增加搜索文本 且得出总数量
            $change_page_func = "get_search([x])";
            if ($page_index != 1 &&
                isset($InputData['search_result_count']) &&
                is_numeric($InputData['search_result_count']) &&
                $InputData['search_result_count'] >= 0
            ) {
                //如果页面已经记录过搜索结果总数量
                $topicList = $myTopic->topic_list(
                    $InputData["list_type"],
                    $topic_list_id, $page_index,
                    $CfgPara->pagesize,
                    $InputData['search_text']);
                $topicCount = $InputData['search_result_count'];
            } else {
                //如果页面为第一页 或没记录过总数量
                $topicList = $myTopic->topic_list(
                    $InputData["list_type"],
                    $topic_list_id, $page_index,
                    $CfgPara->pagesize,
                    $InputData['search_text'], TRUE);
                $topicCount = $myTopic->topic_list_count;
            }
            //返回的结果用连续两个||符号分隔 结果数量与内容
            echo $topicCount . '||';
        } else {
            $change_page_func = "topic_page_change({$InputData['list_type']},[x])";
            if ($topicCount > 0) {
                $topicList = $myTopic->topic_list(
                    $InputData["list_type"],
                    $topic_list_id,
                    $page_index,
                    $CfgPara->pagesize);
            } else {
                $topicList = $myTopic->topic_list(
                    $InputData["list_type"],
                    $topic_list_id,
                    $page_index,
                    $CfgPara->pagesize,
                    null,
                    TRUE);
                $topicCount = $myTopic->topic_list_count;
            }
        }

        if (is_string($topicList)) {
            echo($topicList);
            goto page_end;
        }
        if (isset($change_page_func) && $CfgPara->pagesize > 0) {
            // 连接分页类 在列表最后加入分页栏
            require_once("{$CfgPara->root}/class/paginate.class.php");
            $myPaginate = new paginate_c();
            $myPaginate->change_func = $change_page_func;
            $paginateMsg = $myPaginate->paginate($page_index, ceil($topicCount / $CfgPara->pagesize));
        }
    }
    if (!isset($InputData['page_change']))
        require("{$viewRoot}topic{$topic_show_view}_list{$viewEx}");//如果为初始加载则连接整个视图
    elseif ((isset($InputData['page_iscroll_load']) && $InputData['page_iscroll_load'] == 2))
        require("{$viewRoot}topic{$topic_show_view}_list_content{$viewEx}");//加载 则仅连接内容
    else
        require("{$viewRoot}topic{$topic_show_view}_list_page{$viewEx}");//如果为页面切换 则仅连接页面
    if ($InputData["list_type"] == topic_m::ListMine ||
        $InputData["list_type"] == topic_m::ListEdit ||
        $InputData["list_type"] == topic_m::ListCheck
    ) {
        if ($isTablet === FALSE)
            require("{$viewRoot}menu_r_topic_list{$viewEx}");
    }

}

page_end:;